package com.conn;

import java.net.*;
import java.io.*;
import java.util.*;

//class RegisterXml implements XmlOpertor {
//    RegisterInfo ri;
//    RegisterXml(RegisterInfo ri) {
//        this.ri = ri;
//    }
//    public String toXml() {
//    }
//}

//class LoginXml {
//    public static String toXml(ClientInfo ri) {
////            addElement(doc, "username", ri.username).
////            addElement(doc, "passwd", ri.passwd);
//        return null;
//    }
//}

public class Client {
    Socket cli;
    ClientState state;
    Parser parser;
    Packer packer;

    public Client() throws IOException {
        String ipaddr = GlobalData.getServerIp();
        int port = GlobalData.getServerPort();

        System.out.println("connect to ip:"+ipaddr+" with port:"+port);

        cli = new Socket(ipaddr, port);
        System.out.println("init client ok.");

        state = new WaitLoginState();
        parser = new Parser1();
        packer = new Packer1();
    }

    public boolean clientRegister(RegisterInfo ri) {
//        System.out.println("name: "+ri.name);
//        System.out.println("sex: "+ri.sex);
//        System.out.println("birthday: "+ri.birthday);
//        System.out.println("phone: "+ri.phone);
//        System.out.println("country: "+ri.country);
//        System.out.println("home: "+ri.home);
        return state.register(cli, packer.registerPack(ri));
    }

    public boolean clientUnregister(RegisterInfo ri) {
//        return state.unregister(cli, RegisterXml.toXml(ri));
        return false;
    }

    public boolean clientLogin(ClientInfo ci) {
//        return state.login(cli, LoginXml.toXml(ci));
        return false;
    }
}


